package com.example.demo.service;

import com.example.demo.mapper.BlogMapper;
import com.example.demo.mapper.UserMapper;
import com.example.demo.model.BlogInfo;
import com.example.demo.model.UserInfo;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    @Autowired
    private UserMapper userInfoMapper;
    @Autowired
    private BlogMapper blogMapper;
    public UserInfo queryUserByName(String userName) {
        return userInfoMapper.selectByName(userName);
    }



    public UserInfo queryUserById(Integer userId) {
        return userInfoMapper.selectById(userId);
    }

    public UserInfo getAuthorInfoByBlogId(Integer blogId) {

        BlogInfo blogInfo = blogMapper.selectById(blogId);
        if(blogInfo== null && blogInfo.getUserId()<1){
            return null;
        }
        UserInfo userInfo = userInfoMapper.selectById(blogInfo.getUserId());
        return userInfo;
    }
}
